/*
 *  HarmonicSound.cpp
 *  SoundController0002
 *
 *  Created by jiro on 11/06/16.
 *  Copyright 2011 jiro music. All rights reserved.
 *
 */

#include "HarmonicSound.h"

#include "../../sc/Common/WellTemperament.h"
#include <sstream>

namespace sc
{
namespace hs
{
	HarmonicSound::HarmonicSound()
		: Sound()
	{}

	HarmonicSound::HarmonicSound( Sound::WaveType type, ::sc::Note::MidiNumber midiNumber, double nthOfHarmonic )
		: Sound( type, midiNumber ),
		  nthOfHarmonic( nthOfHarmonic )
	{}

	HarmonicSound::HarmonicSound( double frequency, double nthOfHarmonic )
		: Sound( frequency ),
		  nthOfHarmonic( nthOfHarmonic )
	{}

	HarmonicSound::HarmonicSound( Sound::WaveType type, ::sc::Note::MidiNumber midiNumber, double nthOfHarmonic, double dynamics )
		: Sound( type, midiNumber, dynamics  ),
		  nthOfHarmonic( nthOfHarmonic )
	{}

	HarmonicSound::HarmonicSound( double frequency, double nthOfHarmonic, double dynamics )
		: Sound( frequency, dynamics )
	{}

	double HarmonicSound::GetNthOfHarmonic() const
	{
		return nthOfHarmonic;
	}

	double HarmonicSound::GetFrequency() const
	{
		return GetNthOfHarmonic() * Sound::GetFrequency();
	}

	//	for stl map / set
	bool HarmonicSound::operator < ( const HarmonicSound& rhs ) const
	{
		if ( Sound::operator != ( static_cast< const Sound& >( rhs ) ) )
		{
			return Sound::operator < ( static_cast< const Sound& >( rhs ) );
		}
		if ( nthOfHarmonic != rhs.nthOfHarmonic )
		{
			return nthOfHarmonic < rhs.nthOfHarmonic;;
		}
		return false;
	}

	bool HarmonicSound::operator == ( const HarmonicSound& rhs ) const
	{
		if ( Sound::operator == ( rhs ) and nthOfHarmonic == rhs.nthOfHarmonic )
		{
			return true;
		}
		return false;
	}

	bool HarmonicSound::operator != ( const HarmonicSound& rhs ) const\
	{
		return not ( * this == rhs );
	}

	std::string HarmonicSound::ToString() const
	{
		std::stringstream ss;
		ss << Sound::ToString() << ", nthOfHarmonic: " << nthOfHarmonic
			<< ", " << nthOfHarmonic * WellTemperament::GetFrequency( GetMidiNumber() ) << "Hz";
		return ss.str();
	}

}
}
